<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath =
            request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                    + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link href="static/easyui/themes/default/easyui.css" rel="stylesheet"/>
    <link href="static/easyui/themes/icon.css" rel="stylesheet"/>
    <script type="text/javascript" src="static/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="static/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="static/util.js"></script>
</head>
<body>
<table id="dg" class="easyui-datagrid" data-options="toolbar:'#tb'">
</table>

<script>
  $(function () {
    $('#dg').datagrid({
      nowrap: false,
      pagination: true,
      pageList: [2, 5, 10, 20, 30],
      pageSize: 5,
      url: "notice/page",
      showHeader: true,
      columns: [[
        {field: 'title', title: '标题', width: 150},
        {field: 'created', title: '时间', width: 200},
        {
          field: 'fileName', title: '图片', width: 200, formatter: function (value, row, index) {
            var options = {
              width: 1000,
              height: 500,
              title: "查看图片",
              url: "manage/showImage.jsp?fileName=" + row.image
            };

            return "<button onclick='openTopWindow(" + JSON.stringify(options) + ")'>" + "查看图片"
                + "</button>";
          }
        },
        {
          field: 'operation', title: '操作', width: 200, formatter: function (value, row, index) {
            var value = "<button onclick='showDetail(" + row.id + ")'>查看详情</button>&emsp;";
            value += "<button onclick='remove(" + row.id + ")'>删除</button>&emsp;"
                + "<button onclick='edit(" + row.id + ")'>修改</button>"

            return value;
          }
        }
      ]]
    });

  });

  function showDetail(id) {
    openTopWindow({
      url: 'manage/showNoticeDetail.jsp?id=' + id,
      title: '失物招领详情'
    })
  }

  function remove(id) {
    $.messager.confirm('提示', '确认删除？', function (r) {
      if (r) {
        $.ajax({
          url: 'notice/delete.do',
          type: 'post',
          data: {id: id},
          success: function (response) {
            $.messager.alert('提示信息', response.message, 'info', function () {
              $('#dg').datagrid('reload');
            });
          }
        })
      }
    });
  }

  function edit(id) {
    openTopWindow({
      url: 'manage/editNotice.jsp?id=' + id,
      title: '编辑公告信息',
      fit: true
    })
  }

</script>
</body>
</html>
